/*
 *      Author: Guannan Ma
 *      @mythmgn
 *      Whatever license applied
 */

#include "base.h"

#ifndef BASE_LIB_LIBHASHTABLE_H
#define BASE_LIB_LIBHASHTABLE_H

#ifdef __cplusplus
extern "C"
{
#endif

    typedef struct hItem {
        struct hItem *next;
        void *content;
        char *key;
    } hItem;

    typedef struct hTab {
        hItem *hiList;
        unsigned int size;
    } hTab;

    /*! @fn
            initHashTable
        @description
            I.g.
                if (NULL==(hcf=(hTab *)malloc(sizeof(hTab))))
                    return NULL;
    */
    hTab *initHashTable(int initSize);

    /** \brief The key will be malloced inside hItem.
               But the content will be only stored as a pointer in hItem.
     * \param ph hTab*
     * \param key char*
     * \param content void*
     * \return BOOL
     *
     */
    BOOL putHashItem(hTab *ph,char *key,void *content);

    void* getHashItem(hTab *ph,const char *key);

    void* delHashItem(hTab *ph,char *key);

    BOOL freeHashTable(hTab *h,BOOL delContent,void (*handleContentFunc)(void *content));

#ifdef __cplusplus
}
#endif

#endif // LIB_HASTABLE_H_INCLUDED
